package com.usian.admin.controller;

import com.usian.admin.service.AdChannerService;
import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理",tags = "channer",description = "频道管理API")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannerService adChannerService;

    @PostMapping("/list")
    @ApiOperation(value = "频道分页列表查询",notes = "根据频道名称查询频道列表")
    @ApiImplicitParam(name = "dto",type = "ChannerDto",value = "分页及名称信息")
    @Override
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannerService.findByNameAndPage(dto);
    }

    @PostMapping("/save")
    @ApiOperation(value = "添加频道列表",notes = "添加频道列表")
    @ApiImplicitParam(name = "adChanner",type = "AdChanner",value = "添加的频道信息")
    @Override
    public ResponseResult addAdChannel(@RequestBody AdChannel adChannel) {
        return adChannerService.addAdChannel(adChannel);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改频道列表",notes = "修改频道列表")
    @ApiImplicitParam(name = "adChanner",type = "AdChanner",value = "修改的频道信息")
    @Override
    public ResponseResult updateAdChannel(@RequestBody AdChannel adChannel) {
        return adChannerService.updateAdChanner(adChannel);
    }

    @GetMapping("/del")
    @ApiOperation(value = "删除频道列表",notes = "根据id删除频道列表")
    @ApiImplicitParam(name = "id",type = "Integer",value = "要删除的频道的id")
    @Override
    public ResponseResult deleteAdChanner(Integer id) {
        return adChannerService.deleteAdChanner(id);
    }


    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        List<AdChannel> list = adChannerService.list();
        return ResponseResult.okResult(list);
    }
}
